package com.example.webapp.repository;

import com.example.webapp.entity.Project;
import com.example.webapp.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Long> {
    boolean existsByName(String name);
    
    List<Project> findAllByUserOrderByCreatedAtDesc(User user);
    
    @Query("SELECT p FROM Project p WHERE p.user.id = :userId ORDER BY p.createdAt DESC")
    List<Project> findAllByUserIdOrderByCreatedAtDesc(@Param("userId") Long userId);
} 